//
//  advisoryViewController.m
//  One Construction
//
//  Created by apple on 2019/9/7.
//  Copyright © 2019 apple. All rights reserved.
//

#import "advisoryViewController.h"
#import "advisoryTableViewCell.h"
@interface advisoryViewController ()<UITableViewDelegate,UITableViewDataSource,advistoryDelegate>
@property(nonatomic,strong)UITextField *messageTextField;
@property(nonatomic,strong)UITableView *TableView;
@property(nonatomic,strong)NSArray *dataArr;
@property(nonatomic,strong)NSArray *leftArr;
@property(nonatomic,strong)NSString *nameString;
@property(nonatomic,strong)NSString *phoneString;
@property(nonatomic,strong)NSString *emailString;
@property(nonatomic,strong)UIButton *submitBtn;

@end

@implementation advisoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1.0];
    self.navigationItem.title = @"咨询";
    self.dataArr = [[NSArray alloc]initWithObjects:@"请输入联系人姓名", @"请输入联系人电话",@"请输入联系人邮箱",nil];
self.leftArr = [[NSArray alloc]initWithObjects:@"姓名", @"电话",@"邮箱",nil];
    [self creatUI];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)creatUI{
    myLable *messlable = [[myLable alloc]initWithFrame:CGRectMake(22,AppNavitionHright+ 11, 100, 25)];
    [self.view addSubview:messlable];
    [messlable setLabletextColor:[UIColor blackColor] Text:@"留言内容" TextFont:18];
    
    [self.view addSubview:self.messageTextField];
    [self.messageTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
         make.right.mas_offset(-10);
        make.height.mas_equalTo(180);
        make.top.mas_equalTo(messlable.mas_bottom).mas_offset(9);
    }];
    
    [self.view addSubview:self.TableView];
    [self.TableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
         make.right.mas_offset(-10);
         make.height.mas_equalTo(self.dataArr.count*50);
         make.top.mas_equalTo(self.messageTextField.mas_bottom).mas_offset(10);
    }];
    
    [self.view addSubview:self.submitBtn];
    [self.submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.right.mas_offset(0);
        make.height.mas_equalTo(50);
        make.bottom.mas_offset(0);
        
    }];
    [self.submitBtn addTarget:self action:@selector(clickSubmitBtn) forControlEvents:UIControlEventTouchUpInside];
    
    
    
}
- (void)clickSubmitBtn{
    
    if (self.messageTextField.text.length == 0) {
        if ([judgeString isBlankString:_nameString]) {
            [ProgressHUD showText:@"请先输入联系人的姓名" icon:[UIImage  imageNamed:@""] mode:MBProgressHUDModeText onView:self.view duration:1.0];
        }
        else{
            if ([judgeString isBlankString:_phoneString]) {
                [ProgressHUD showText:@"请先输入联系人的手机号" icon:[UIImage  imageNamed:@""] mode:MBProgressHUDModeText onView:self.view duration:1.0];
            }
            else{
                
                if ([judgeString isBlankString:_emailString]) {
                    [ProgressHUD showText:@"请先输入联系人的邮箱" icon:[UIImage  imageNamed:@""] mode:MBProgressHUDModeText onView:self.view duration:1.0];
                }
                else{
                    [ProgressHUD showText:@"提交中.." icon:[UIImage  imageNamed:@""] mode:MBProgressHUDModeIndeterminate onView:self.view duration:1.0];
                    __weak __typeof__(self)weakSelf = self;
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        [weakSelf.navigationController popViewControllerAnimated:YES];
                        
                        
                    });
                }
            }
        }
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"advisoryCell";
    advisoryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    cell.rightTextField.placeholder = self.dataArr[indexPath.row];
    cell.leftLable.text = self.leftArr[indexPath.row];
    cell.mydelegate = self;
    cell.index = indexPath;
    
    
    return cell;
}

- (void)clickTextFieldIndexPath:(NSIndexPath *)index Str:(NSString *)str{
    if (index.row ==0) {
        _nameString = str;
    }
    else if (index.row == 1){
        _phoneString = str;
        
    }
    else if (index.row == 2){
        _emailString = str;
        
    }
}
- (UITextField *)messageTextField{
    if (!_messageTextField) {
        _messageTextField = [[UITextField alloc]init];
        _messageTextField.placeholder = @"请在此输入留言内容，我们会尽快处理！";
        _messageTextField.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
        _messageTextField.layer.cornerRadius = 10;
        
    }
    return _messageTextField;
    
}


-(UITableView *)TableView{
    if (!_TableView) {
        
        _TableView = [[UITableView alloc]init];
        _TableView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
        _TableView.layer.cornerRadius = 10;
        _TableView.delegate = self;
        _TableView.dataSource  =self;
        _TableView.bounces = NO;
        [_TableView  registerClass:[advisoryTableViewCell class] forCellReuseIdentifier:@"advisoryCell"];
        
        
    }
    return _TableView;
}
- (UIButton *)submitBtn{
    if (!_submitBtn) {
        _submitBtn = [[UIButton alloc]init];
        _submitBtn.backgroundColor =  [UIColor colorWithRed:31/255.0 green:78/255.0 blue:196/255.0 alpha:1.0];
        [_submitBtn setTitle:@"发送" forState:UIControlStateNormal];
        _submitBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
        [_submitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    return _submitBtn;
}

@end
